<?php
namespace app\admin\controller;
use app\admin\model\Opinion as OpinionModel;

//意见反馈管理类
class Opinion extends Base
{
    /**
     * 意见列表
     */
    public function opinionLst()
    {
        $list = OpinionModel::order('on_create_time DESC')->paginate(10);

        $data = displayJson($list);

        $arr  = json_decode($data,true);

        $userIds   = array();
        $newArr    = $arr['data'];

        foreach ($newArr as $val) {
            $userIds[] = $val['on_uid'];
        }

        $user_list = $this->getUserEmailByIds($userIds);

        foreach ($newArr as $key => $val) {
            $newArr[$key]['on_uid']    = $user_list[$val['on_uid']]['us_email'];
            $newArr[$key]['us_status'] = $user_list[$val['on_uid']]['us_status'];
        }

        $arr['data'] = $newArr;

        $info['code']    = '200';
        $info['data']    = $arr;
        echo displayJson($info);die;
    }

    /**
     * 删除意见
     */
    public function opinionDel()
    {
        $id  = input('id');

        $del = db('opinion',[],false)->where('on_id',$id)->delete();

        if ($del) {
            $info['code']    = '200';
            $info['message'] = '删除成功';
            echo displayJson($info);die;
        } else {
            $info['code']    = '400';
            $info['message'] = '删除失败';
            echo displayJson($info);die;
        }
    }
}